package com.nexgo.payment.trans.setting.terminalkey;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.nexgo.payment.R;
import com.nexgo.payment.constrant.TransType;
import com.nexgo.payment.trans.download.DownloadTransActivity;
import com.nexgo.payment.ui.ListMenuActivity;
import com.nexgo.payment.util.AppUtils;
import com.nexgo.payment.util.ByteUtil;
import com.nexgo.payment.util.ToastUtils;

import java.util.ArrayList;

/**
 * 终端密钥管理
 */
public class KeyManageActivity extends ListMenuActivity {

    private ArrayList<Integer> mItemList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
    }

    @Override
    protected String getActivityTitle() {
        return getString(R.string.terminal_key_management_settings);
    }

    private void initView() {
        mItemList = new ArrayList<>();
        mItemList.add(R.string.setup_master_key);
        mItemList.add(R.string.setup_master_key_value);
        mItemList.add(R.string.work_master_key_down);
        if(!ByteUtil.checkDownKeyIsSucc()){
            mItemList.add(R.string._key_down);
        }
        for (Integer i : mItemList) {
            addItem(i);
        }
    }

    @Override
    protected void onItemClick(int position) {
        int item = mItemList.get(position);
        switch (item) {
            case R.string.setup_master_key:
                startActivity(SetupMasterKeyActivity.newInstance(this));
                break;
            case R.string.setup_master_key_value:
                startActivity(SetupMasterKeyValueActivity.newInstance(this));
                break;
            case R.string.work_master_key_down:
                startActivity(DownloadTransActivity.newInstance(this, TransType.WORK_MASTER_KEY_DOWN));
                break;
            case R.string._key_down:
                if(!AppUtils.checkPrograme("com.xgd.payment.downloadkey","MainActivity")){
                    ToastUtils.showToast("远程下载密钥程序未安装");
                }else{
                    Intent intent = new Intent();
                   /* intent.addCategory(Intent.CATEGORY_LAUNCHER);
                    ComponentName cn = new ComponentName("com.xgd.payment.downloadkey","MainActivity");
                    intent.setComponent(cn);*/
                    intent.setAction("com.xgd.payment.downloadkey");
                    startActivity(intent);
                }

                break;
            default:
                break;
        }
    }

    public static Intent newInstance(Context context) {
        return new Intent(context, KeyManageActivity.class);
    }
}
